Feistel Cipher Structure
Module 03 / Lesson 04
Structural Walkthrough
What is a Feistel Cipher?
A Feistel cipher is a symmetric structure used in many block ciphers. It transforms an input block through multiple identical rounds. In each round, the data is split into two halves, and a Round Function (F) is applied to one half.
Structure Rules:
- Split input block into two equal halves (L & R).
- The new Left ($L_i$) becomes the previous Right ($R_{i-1}$).
- The new Right ($R_i$) is the XOR of $L_{i-1}$ and $F(R_{i-1}, K_i)$.
Key Properties:
- Invertible: Encryption and decryption use the same structure.
- Flexible: Function F doesn't need to be invertible.
- Efficiency: Same hardware/software for both processes.
Python Implementation (Feistel Logic)
def round_function(right_half, key):
# This can be any complex function (S-Boxes, etc.)
# For demo: (Right XOR Key) shifted
return (right_half ^ key) << 1
def feistel_round(left, right, key):
# 1. New Left = Old Right
new_left = right
# 2. New Right = Old Left XOR F(Old Right, Key)
f_result = round_function(right, key)
new_right = left ^ f_result
return new_left, new_right
# Example Execution
L, R = 0xABCD, 0x1234
K = 0xFF00
L_next, R_next = feistel_round(L, R, K)
print(f"Round Result: L={hex(L_next)}, R={hex(R_next)}")